package com.rytx.web.controller.ysp;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.rytx.common.core.domain.model.ArtUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rytx.common.annotation.Log;
import com.rytx.common.core.controller.BaseController;
import com.rytx.common.core.domain.AjaxResult;
import com.rytx.common.enums.BusinessType;
import com.rytx.system.domain.ArtPartner;
import com.rytx.system.service.IArtPartnerService;
import com.rytx.common.utils.poi.ExcelUtil;
import com.rytx.common.core.page.TableDataInfo;

/**
 * 合作商管理Controller
 *
 * @author zhangzb
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/partner/partner")
public class ArtPartnerController extends BaseController
{
    @Autowired
    private IArtPartnerService artPartnerService;

    /**
     * 查询合作商管理列表
     */
    @PreAuthorize("@ss.hasPermi('partner:partner:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArtPartner artPartner)
    {
        startPage();
        List<ArtPartner> list = artPartnerService.selectArtPartnerList(artPartner);
        return getDataTable(list);
    }

    /**
     * 查询合作商管理列表
     */
    @GetMapping("/zfbUserList")
    public TableDataInfo zfbUserlist(ArtUser artUser)
    {
        List<ArtUser> list = artPartnerService.selectArtUserList(artUser);
        return getDataTable(list);
    }

    /**
     * 导出合作商管理列表
     */
    @PreAuthorize("@ss.hasPermi('partner:partner:export')")
    @Log(title = "合作商管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArtPartner artPartner)
    {
        List<ArtPartner> list = artPartnerService.selectArtPartnerList(artPartner);
        ExcelUtil<ArtPartner> util = new ExcelUtil<ArtPartner>(ArtPartner.class);
        util.exportExcel(response, list, "合作商管理数据");
    }

    /**
     * 获取合作商管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('partner:partner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(artPartnerService.selectArtPartnerById(id));
    }

    /**
     * 新增合作商管理
     */
    @PreAuthorize("@ss.hasPermi('partner:partner:add')")
    @Log(title = "合作商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArtPartner artPartner)
    {
        return toAjax(artPartnerService.insertArtPartner(artPartner));
    }

    /**
     * 修改合作商管理
     */
    @PreAuthorize("@ss.hasPermi('partner:partner:edit')")
    @Log(title = "合作商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArtPartner artPartner)
    {
        return toAjax(artPartnerService.updateArtPartner(artPartner));
    }

    @Log(title = "绑定支付宝用户", businessType = BusinessType.UPDATE)
    @PostMapping("/bindZfbUser")
    public AjaxResult bindZfbUser(@RequestBody Map<String, Object> map)
    {
        return toAjax(artPartnerService.bindZfbUser(map));
    }

    /**
     * 删除合作商管理
     */
    @PreAuthorize("@ss.hasPermi('partner:partner:remove')")
    @Log(title = "合作商管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(artPartnerService.deleteArtPartnerByIds(ids));
    }

    @GetMapping("/generateQRCode/{partnerId}")
    public String generateQRCode(@PathVariable("partnerId") String partnerId) {
        return artPartnerService.generateQRCode(partnerId);
    }

}
